<template>
	<view class="container ptb_12 plr_16">
		<view class="height_70 br_12 bc_primary pr fx aic fc_fff flow_h">
			<view class="fx_1 ptb_14 plr_16">
				<view class="fz_12">
					今日已转换积分
				</view>
				<view class="mt_2 fz_16 fb">
					{{dataInfo.integral||0}}
				</view>
			</view>
			<view class="pa r_0 l_0 mlr_auto width_1 height_20 bc_fff">

			</view>
			<view class="fx_1 ptb_14 plr_16">
				<view class="fz_12">
					今日已获得金豆
				</view>
				<view class="mt_2 fz_16 fb">
					{{dataInfo.youjiadou||0}}
				</view>
			</view>
			<image class="width_91 height_73 pa " src="@/static/images/mission_bg.png" mode="" style="right: -8rpx;">
			</image>
		</view>
		<view class="mt_18 pt_8 fz_12" v-for="item,index in dataInfo.detailList" :key="index">
			<view v-if="item.type==4">
				推荐用户购买商品可将商品金额{{item.currencyRatio||''}}%的积分转换为金豆
			</view>
			<view v-else>
				{{getType(item).name}}即可将{{item.integral||''}}积分转换为{{item.youjiadou||''}}金豆
			</view>
			<view class="fx aic jcb">
				<view v-if="item.type == 1 || item.type == 2">
					今日最多可转换{{item.dailyIntegral||0}}积分，已转换<text class="fc_primary">{{item.todayIntegral||0}}</text>积分
				</view>
				<view v-else>
					今日已转换<text class="fc_primary">{{item.todayIntegral||0}}</text>积分
				</view>
				<button class="custom_btn default fz_12 br_40 lh_25 plr_12 minw_72 boc_primary" style="color: #FE5A1C;"
					@click="handleUrl(getType(item))">{{getType(item).btnName}}</button>
			</view>
		</view>
	</view>
</template>

<script>
	import api from '@/service/config/api.js'
	export default {
		data() {
			return {
				dataInfo: {},
				ruleInfo: {},
			};
		},
		computed: {
			getType() {
				return (data) => {
					switch (data.type) {
						case 1:
							return {
								name: '转发商品',
									btnName: data.todayIntegral?'继续转发':'去转发',
									url: 'home'
							}
						case 2:
							return {
								name: '每浏览一个商品',
									btnName: data.todayIntegral?'继续浏览':'去浏览',
									url: 'home'
							}
						case 3:
							return {
								name: '每邀请一个新用户注册',
									btnName: data.todayIntegral?'继续邀请':'去邀请',
									url: '/pages/common/pages/invite'
							}
						case 4:
							return {
								btnName: data.todayIntegral?'继续邀请':'去邀请',
									url: '/pages/common/pages/invite'
							}
						case 5:
							return {
								name: '好评商品',
									btnName: data.todayIntegral?'继续评价':'去评价',
									url: '/pages/person/pages/order'
							}
						default:
							break
					}
				}
			}
		},
		onLoad() {
			this.getData()
		},
		methods: {
			getData() {
				this.$utils.loading()
				api.get('/user/api/user/getIntegralSet', {

				}, {
					noHideLoading: true
				}).then(res => {
					this.ruleInfo = res.data
					api.get('/user/api/myTask').then(res1 => {
						this.dataInfo = res1.data
					})
				}).catch(() => {
					uni.hideLoading()
				})
			},
			handleUrl(data) {
				if (data.url == 'home') {
					return uni.switchTab({
						url: '/pages/index/index'
					})
				}
				uni.navigateTo({
					url: data.url
				})
			}
		}
	}
</script>

<style lang="scss">
	@include color_page;
</style>

<style lang="scss" scoped>

</style>